enum FINDBOXMSG_BOX_MSG_st{
    //%block="xCoordinate"
    x,
    //%block="yCoordinate"
    y,
    //%block="squareFrameWidth"
    w,
    //%block="squareFrameHeight"
    h,
    //%block="msg"
    msg

}
enum FINDBOXMSG_BOX_st{
    //%block="xCoordinate"
    x,
    //%block="yCoordinate"
    y,
    //%block="squareFrameWidth"
    w,
    //%block="squareFrameHeight"
    h,


}

enum k210_PACKET_FUNCTION_BOX_ST{
    //%block="color learning and recognition"
    K210_COLOR_RECOGNITION,
    //%block="facial detection"
    K210_FIND_FACE_YOLO,
    //%block="facial feature detection"
    K210_FIND_FACEFEATURE,
    //%block="red tracking"
    K210_FIND_RED_FOLLOW,

}

enum k210_PACKET_FUNCTION_BOX_MSG_ST{
    //%block="shopsavvy barcode scanner"
    K210_FIND_BARCODES,
    //%block="qr code recognition"
    K210_FIND_QRCODES,
    //%block="machine code recognition"
    K210_FIND_APRILTAGS,
    //%block="mask detection"
    K210_FIND_FACEMASK,
    //%block="object detection"
    K210_FIND_OBJECT,
    //%block="roadsign tracking"
    K210_FIND_SIGNPOST_FOLLOW,
    //%block="digital card recognition action"
    K210_FIND_DIGITAL_CARD,
    //%block="garbage classification"
    K210_GARBAGE_SORTING,
    //%block="multiple color recognition"
    K210_COLOR_SORTING,
    //%block="facial recognition"
    K210_FIND_FACE_RECOGNITION,
}
enum k210_PACKET_FUNCTION_MSG_ST{
    //%block="autonomous learning classification"
    K210_FIND_SELF_LEARNING,
    //%block="number recognition"
    K210_FIND_DIGITAL,
}

enum k210_PACKET_FUNCTION{
    //%block="color learning and recognition"
    K210_COLOR_RECOGNITION,
    //%block="facial detection"
    K210_FIND_FACE_YOLO,
    //%block="facial feature detection"
    K210_FIND_FACEFEATURE,
    //%block="facial recognition"
    K210_FIND_FACE_RECOGNITION,
    //%block="red tracking"
    K210_FIND_RED_FOLLOW,
    //%block="shopsavvy barcode scanner"
    K210_FIND_BARCODES,
    //%block="qr code recognition"
    K210_FIND_QRCODES,
    //%block="machine code recognition"
    K210_FIND_APRILTAGS,
    //%block="mask detection"
    K210_FIND_FACEMASK,
    //%block="object detection"
    K210_FIND_OBJECT,
    //%block="roadsign tracking"
    K210_FIND_SIGNPOST_FOLLOW,
    //%block="digital card recognition action"
    K210_FIND_DIGITAL_CARD,
    //%block="garbage classification"
    K210_GARBAGE_SORTING,
    //%block="multiple color recognition"
    K210_COLOR_SORTING,
    //%block="autonomous learning classification"
    K210_FIND_SELF_LEARNING,
    //%block="number recognition"
    K210_FIND_DIGITAL,
}

//% color="#33CCFF" iconWidth=50 iconHeight=40
namespace WonderK210{

      //% block="initialization WonderK210 softSerialPort RX[RX]TX[TX]baudRate9600" blockType="command"
      //% RX.shadow="dropdown" TX.shadow="dropdown" TX.options="PIN_TX" RX.options="PIN_RX"   
      export function AI_init(parameter: any, block: any) {
        let rx = parameter.RX.code
        let tx = parameter.TX.code
        Generator.addInclude('WonderK210Include', '#include <WonderK210.h>');
        Generator.addObject('WonderK210Object', 'WonderK210*',`xyxkc_wk;`);

        Generator.addSetup(`xyxkc_wkSetup`,`xyxkc_wk = (WonderK210*)malloc(sizeof(WonderK210));`)
        Generator.addSetup(`xyxkc_wk.serial_begin_Setup`,`xyxkc_wk->serial_begin(${rx}, ${tx});`)

      }
    //% block="WonderK210 get a message once" blockType="command"
    export function AI_update_data(parameter: any, block: any) {
      Generator.addCode(`xyxkc_wk->update_data();`)
    }
    //% block="WonderK210 analysis[k210_PACKET_FUNCTION_BOX_ST]news" blockType="command"
    //% k210_PACKET_FUNCTION_BOX_ST.shadow="dropdown"  k210_PACKET_FUNCTION_BOX_ST.options="k210_PACKET_FUNCTION_BOX_ST"
    export function get_Find_Box_Msg_st(parameter: any, block: any) {
        let k210packet_function = parameter.k210_PACKET_FUNCTION_BOX_ST.code
        Generator.addObject(`Find_Box_stObject_${k210packet_function}`,'Find_Box_st*',`xyxkc_result_${k210packet_function};`);
        Generator.addSetup(`xyxkc_result_Setup_${k210packet_function}`,` xyxkc_result_${k210packet_function} = (Find_Box_st*)malloc(sizeof(Find_Box_st));`)
        Generator.addCode(`bool xyxkc_rt_${k210packet_function} = xyxkc_wk->recive_box(xyxkc_result_${k210packet_function} , ${k210packet_function});`)
      }

    //% block="WonderK210 analysis[k210_PACKET_FUNCTION_BOX_MSG_ST]news" blockType="command"
    //% k210_PACKET_FUNCTION_BOX_MSG_ST.shadow="dropdown"  k210_PACKET_FUNCTION_BOX_MSG_ST.options="k210_PACKET_FUNCTION_BOX_MSG_ST"
    export function AI_get_Find_Box_st(parameter: any, block: any) {
        let k210packet_function = parameter.k210_PACKET_FUNCTION_BOX_MSG_ST.code
        Generator.addObject(`Find_Box_stObject_${k210packet_function}`,'Find_Box_Msg_st*',`xyxkc_result_${k210packet_function};`);
        Generator.addSetup(`xyxkc_result_Setup_${k210packet_function}`,` xyxkc_result_${k210packet_function} = (Find_Box_Msg_st*)malloc(sizeof(Find_Box_Msg_st));`)
        Generator.addCode(`bool xyxkc_rt_${k210packet_function} = xyxkc_wk->recive_box_msg(xyxkc_result_${k210packet_function} , ${k210packet_function});`)
    }
    //% block="WonderK210 analysis[k210_PACKET_FUNCTION_MSG_ST]news" blockType="command"
    //% k210_PACKET_FUNCTION_MSG_ST.shadow="dropdown"  k210_PACKET_FUNCTION_MSG_ST.options="k210_PACKET_FUNCTION_MSG_ST"
    export function AI_get_Find_Msg_st(parameter: any, block: any) {
        let k210packet_function = parameter.k210_PACKET_FUNCTION_MSG_ST.code
        Generator.addObject(`Find_Box_stObject_${k210packet_function}`,'Find_Msg_st*',`xyxkc_result_${k210packet_function};`);
        Generator.addSetup(`xyxkc_result_Setup_${k210packet_function}`,` xyxkc_result_${k210packet_function} = (Find_Msg_st*)malloc(sizeof(Find_Msg_st));`)
        Generator.addCode(`bool xyxkc_rt_${k210packet_function} = xyxkc_wk->recive_msg(xyxkc_result_${k210packet_function} , ${k210packet_function});`)
    }

    //% block="WonderK210 analysis[k210_PACKET_FUNCTION]messageSuccessful" blockType="boolean"
    //% k210_PACKET_FUNCTION.shadow="dropdown"  k210_PACKET_FUNCTION.options="k210_PACKET_FUNCTION"
    export function AI_Dataisavailable(parameter: any, block: any) {
        let k210packet_function = parameter.k210_PACKET_FUNCTION.code
        Generator.addCode(`xyxkc_rt_${k210packet_function}`)
    }

    //% block="WonderK210 obtain[k210_PACKET_FUNCTION_BOX_ST]of[FINDBOXMSG_BOX_st]valueOf" blockType="reporter"
    //% k210_PACKET_FUNCTION_BOX_ST.shadow="dropdown"  k210_PACKET_FUNCTION_BOX_ST.options="k210_PACKET_FUNCTION_BOX_ST"
    //% FINDBOXMSG_BOX_st.shadow="dropdown"  FINDBOXMSG_BOX_st.options="FINDBOXMSG_BOX_st"
    export function AI_Find_Box_st(parameter: any, block: any) {
        let findBoxMsg = parameter.FINDBOXMSG_BOX_st.code
        let k210packet_function = parameter.k210_PACKET_FUNCTION_BOX_ST.code
        Generator.addObject(`Find_Box_stObject_${k210packet_function}`,'Find_Box_st*',`xyxkc_result_${k210packet_function};`);
        Generator.addSetup(`xyxkc_result_Setup_${k210packet_function}`,` xyxkc_result_${k210packet_function} = (Find_Box_st*)malloc(sizeof(Find_Box_st));`)
        if (findBoxMsg == "msg"){
            Generator.addCode(`String(xyxkc_result_${k210packet_function}->${findBoxMsg})`)
        }else{
            Generator.addCode(`xyxkc_result_${k210packet_function}->${findBoxMsg}`)
        }
    }



    //% block="WonderK210 obtain[k210_PACKET_FUNCTION_BOX_MSG_ST]of[FINDBOXMSG_BOX_MSG_st]valueOf" blockType="reporter"
    //% FINDBOXMSG_BOX_MSG_st.shadow="dropdown"  FINDBOXMSG_BOX_MSG_st.options="FINDBOXMSG_BOX_MSG_st"
    //% k210_PACKET_FUNCTION_BOX_MSG_ST.shadow="dropdown"  k210_PACKET_FUNCTION_BOX_MSG_ST.options="k210_PACKET_FUNCTION_BOX_MSG_ST"
    export function AI_Find_Box_Msg_st(parameter: any, block: any) {
        let findBoxMsg = parameter.FINDBOXMSG_BOX_MSG_st.code
        let k210packet_function = parameter.k210_PACKET_FUNCTION_BOX_MSG_ST.code
        Generator.addObject(`Find_Box_stObject_${k210packet_function}`,'Find_Box_Msg_st*',`xyxkc_result_${k210packet_function};`);
        Generator.addSetup(`xyxkc_result_Setup_${k210packet_function}`,` xyxkc_result_${k210packet_function} = (Find_Box_Msg_st*)malloc(sizeof(Find_Box_Msg_st));`)
        if (findBoxMsg == "msg"){
            Generator.addCode(`String(xyxkc_result_${k210packet_function}->${findBoxMsg})`)
        }else{
            Generator.addCode(`xyxkc_result_${k210packet_function}->${findBoxMsg}`)
        }

    }



    //% block="WonderK210 obtain[k210_PACKET_FUNCTION_MSG_ST]messageFrom" blockType="reporter"
    //% k210_PACKET_FUNCTION_MSG_ST.shadow="dropdown"  k210_PACKET_FUNCTION_MSG_ST.options="k210_PACKET_FUNCTION_MSG_ST"
    export function AI_Find_Msg_st(parameter: any, block: any) {
        let k210packet_function = parameter.k210_PACKET_FUNCTION_MSG_ST.code
        Generator.addObject(`Find_Box_stObject_${k210packet_function}`,'Find_Msg_st*',`xyxkc_result_${k210packet_function};`);
        Generator.addSetup(`xyxkc_result_Setup_${k210packet_function}`,` xyxkc_result_${k210packet_function} = (Find_Msg_st*)malloc(sizeof(Find_Msg_st));`)
        Generator.addCode(`String(xyxkc_result_${k210packet_function}->msg)`)
    }

    //% block="WonderK210 switchTo[k210_PACKET_FUNCTION]algorithmUntilSuccessful" blockType="command"
    //% k210_PACKET_FUNCTION.shadow="dropdown"  k210_PACKET_FUNCTION.options="k210_PACKET_FUNCTION"
    export function AI_sendFunction(parameter: any, block: any) {
        let k210packet_function = parameter.k210_PACKET_FUNCTION.code
        Generator.addCode(`xyxkc_wk->sendFunction(k210_PACKET_FUNCTION::${k210packet_function});`)
    }



}